package com.tools.Fisco_tools;

import com.common.LO.CompanyGoesLOS;
import com.tools.Fisco.CompanyGoesTGtable;
import lombok.extern.log4j.Log4j2;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.model.TransactionReceipt;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;

@Log4j2
public class CompanyGoesTGtable_tools {
    public static TransactionReceipt insert(String address, Client client, CryptoKeyPair cryptoKeyPair, CompanyGoesLOS companyGoesLO){

        BigDecimal one_thousand = new BigDecimal(1000);
        BigDecimal one_hundred= new BigDecimal(100);
        CompanyGoesTGtable load = CompanyGoesTGtable.load(address, client, cryptoKeyPair);
        BigInteger RegisteredCapital = new BigInteger(companyGoesLO.getRegisteredCapital().multiply(one_hundred).setScale(0, RoundingMode.DOWN).toString());
        BigInteger total_shares = new BigInteger(companyGoesLO.getTotalShares().toString());
        BigInteger offering_price = new BigInteger(companyGoesLO.getOfferingPrice().multiply(one_thousand).setScale(0, RoundingMode.DOWN).toString());
        BigInteger offering_number = new BigInteger(companyGoesLO.getOfferingNumber().toString());
        BigInteger status = new BigInteger(String.valueOf(companyGoesLO.getStatus()));
        CompanyGoesTGtable.Struct0 struct0 =new   CompanyGoesTGtable.Struct0(companyGoesLO.getUnifiedSocialCreditCode(), companyGoesLO.getCompanyName(),RegisteredCapital
        ,total_shares,offering_price,offering_number,status,companyGoesLO.getOfferingType(),companyGoesLO.getOfferingAddress(),companyGoesLO.getCreateDate());
        TransactionReceipt insert = load.insert(struct0);
        return  insert;
    }
}
